package com.pisolution.scheduler.runtime.master.processor;

import com.pisolution.scheduler.datasource.instance.ExecutionState;

import io.netty.channel.Channel;

import java.util.Date;

/**
 * 任务状态改变数据实体.
 *
 * @author sora
 * @version 0.1.0
 */
public class TaskStateEvent {
    /** 任务实例标识. */
    private final int taskId;

    /** 执行任务的工作节点网络地址. */
    private final String host;

    /** 接收工作节点反馈指令的信道. */
    private final Channel channel;

    /** 任务实例的执行路径. */
    private final String executePath;

    /** 任务实例运行日志存储路径. */
    private final String logPath;

    /** 任务实例进程号. */
    private int pid;

    /** 任务实例的执行状态. */
    private final ExecutionState state;

    /** 任务实例开始处理时间. */
    private final Date startTime;

    /** 任务实例结束处理时间. */
    private Date endTime;

    /** 状态更改事件是否来源于确认指令. */
    private final boolean isAck;

    // -------------------------------------------------------------------------------------------------
    //  初始化
    // -------------------------------------------------------------------------------------------------

    /**
     * 初始化 {@link TaskStateEvent}.
     *
     * @param taskId 任务实例标识.
     * @param host 执行任务的工作节点网络地址.
     * @param channel 接收工作节点反馈指令的信道.
     * @param executePath 任务实例的执行路径.
     * @param logPath 任务实例运行日志存储路径.
     * @param state 任务实例的执行状态.
     * @param startTime 任务实例开始处理时间.
     */
    public TaskStateEvent(
        final int taskId,
        final String host,
        final Channel channel,
        final String executePath,
        final String logPath,
        final ExecutionState state,
        final Date startTime
    ) {
        this.taskId = taskId;
        this.host = host;
        this.channel = channel;
        this.executePath = executePath;
        this.logPath = logPath;
        this.state = state;
        this.startTime = startTime;
        this.isAck = true;
    }

    // -------------------------------------------------------------------------------------------------
    //  属性访问
    // -------------------------------------------------------------------------------------------------

    public int getTaskId() {
        return this.taskId;
    }

    public String getHost() {
        return this.host;
    }

    public Channel getChannel() {
        return this.channel;
    }

    public String getExecutePath() {
        return this.executePath;
    }

    public String getLogPath() {
        return this.logPath;
    }

    public ExecutionState getState() {
        return this.state;
    }

    public Date getStartTime() {
        return this.startTime;
    }

    public boolean isAck() {
        return this.isAck;
    }
}
